package com.lyx.service.impl;

import com.lyx.entity.Course;
import com.lyx.entity.Student;
import com.lyx.mapper.CourseMapper;
import com.lyx.service.CourseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * --- Be Humble and Hungry ---
 *
 * @author McMeloxD
 * @date 2024/8/23
 * @desc
 */
@Service
public class CourseServiceImpl implements CourseService {
    @Resource
    private CourseMapper courseMapper;

    @Override
    public List<Course> findAllInfos(String cname) {
        return courseMapper.findAllInfos(cname);
    }

    @Override
    public int addCourse(Course course) {
       if (courseMapper.hasCourse(course.getCname())==null) {
           return courseMapper.addCourse(course);
       }
        return 0;
    }

    @Override
    public int editCourse(Course course) {
        if (courseMapper.hasCourse(course.getCname())==null) {
            return courseMapper.editCourse(course);
        }
        return 0;
    }

    @Override
    public int delICourse(String cname) {
        if (courseMapper.hasStudent(cname).isEmpty()) {
            return courseMapper.delCourse(cname);
        }
        return 0;
    }

    @Override
    public List<Student> students(Integer cid) {
        return courseMapper.student(cid);
    }

    @Override
    public int deletestudent(Integer sid, Integer cid) {
        if (courseMapper.deleteStudent(sid)>0){
            return courseMapper.updateNum(cid);
        }
        return 0;
    }


}
